var app = getApp()
var axios = require("../../utils/core")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        level: 1,
        list: [],
        levels: 5,
    },
    tab: function (e) {
        this.setData({
            level: e.currentTarget.dataset.level, //当前选中等级
            levels: e.currentTarget.dataset.levels //选中当前升级等级
        })
    },
    backtab: function () {
        wx.navigateBack({
            delta: 0,
        })
        // wx.({
        //   url: '/pages/operation/index',
        // })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    rightNow: function (e) {
        var that = this
        var level = e.currentTarget.dataset.level
        if (that.data.levels <= 6) {
            var currentTab = Number(that.data.level) - 1
            wx.showToast({
                title: '请去礼包专区购买礼包升级',
                icon: "none"
            })
            setTimeout(() => {
                wx.navigateTo({
                    url: '/seckill/pages/gift/gift?currentTab=' + currentTab,
                })
            }, 2000)
        } 
        // else if (that.data.levels == 7 && that.data.list.own_level.id < 8) {
        else if (that.data.list.own_level.id==7) {
            wx.showModal({
                showCancel: false,
                content: "自己已经是" + that.data.list.own_level.levelname,
                success(res) {
                    if (res.confirm) {
                        that.setData({
                            level: Number(that.data.level) + 1,
                            levels: Number(that.data.levels) + 1
                        })
                    }
                }
            })
        } 
        else if (that.data.list.own_level.id == 8) {
            wx.showModal({
                showCancel: false,
                content: "已经是最大等级" + that.data.list.own_level.levelname,
                success(res) {
                    if (res.confirm) {
                        that.setData({
                            level: Number(that.data.level),
                            levels: Number(that.data.levels)
                        })
                    }
                }
            })
        } else {
            wx.navigateTo({
                url: '/operation/open/index?level=' + level + '&levels=' + this.data.levels
            })
        }

    },
    onLoad: function (e) {
        var that = this
        that.setData({
            level: e.level,
            levels: e.levels
        })
        axios.post("goods.djts", {}, ((el) => {
            console.log(el,1111);
            that.setData({
                list: el
            })
        }))
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})